書式の設定
CalendarGcComboBoxCellType.Formatプロパティを使用します。
CalendarGcComboBoxCellTypeは、書式を設定することで入力可能な文字種を制限することができます。CalendarGcComboBoxCellTypeに設定可能な文字種等の詳細については、「書式を設定する」で解説しますので、ここではデザイン画面上からCalendarGcComboBoxCellTypeに書式を設定する方法について説明します。
次は入力可能な文字種を全角のアルファベットに限定する例です。なお、文字種の全角および半角は、その文字のShift-JISコードを使って識別されます。
- プロパティウィンドウのFormatプロパティをアクティブした時に表示される「…」ボタンを選択して「CalendarGcComboBoxCellTypeの書式設定」フォームを表示
- リストから「A([全角]大文字アルファベット)」を選択
- OKボタンを選択
同じ書式をコードで設定する場合は次のようになります。
Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan
Dim today As DateTime = DateTime.Today
Dim GcComboBoxCellType As New InputManCell.CalendarGcComboBoxCellType()
GcComboBoxCellType.DropDownStyle = CalendarGridComboBoxStyle.DropDown
GcComboBoxCellType.Format = "A"
GcCalendarGrid1.Content(today).Rows(1).Cells(0).CellType = GcComboBoxCellType
GcCalendarGrid1.ScrollIntoView(today)
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;
var today = DateTime.Today;
var gcComboBoxCellType = new InputManCell.CalendarGcComboBoxCellType();
gcComboBoxCellType.DropDownStyle = CalendarGridComboBoxStyle.DropDown;
gcComboBoxCellType.Format = "A";
gcCalendarGrid1.Content[today].Rows[1].Cells[0].CellType = gcComboBoxCellType;
gcCalendarGrid1.ScrollIntoView(today);
最大文字数の指定
CalendarGcComboBoxCellType.MaxLengthUnitプロパティを使用します。
MaxLengthUnitプロパティを使えば、MaxLengthプロパティでセルへの入力可能文字数を設定する際に文字のカウント方法を指定することができます。MaxLengthUnitプロパティには、次の3つの設定値があります。バイト単位の処理では、各文字のバイト数はShift-JISコードを使って識別されます。
MaxLengthUnitの値 |
説明 |
Char |
文字単位でカウントしますが、サロゲート ぺア文字やIVS(Ideographic Variation Sequence)文字の異体字セレクタ(Variation Selector)は2文字としてカウントされます。 |
Byte |
バイト単位で文字をカウントします。 |
TextElement |
文字単位でカウントします。サロゲート ぺア文字やIVS文字は1文字としてカウントされます。 |
IVS文字はIVSの親となる漢字(以下、親字)の文字コードの後ろに異体字セレクタが付加された構造のため、MaxLengthプロパティの設定値によっては異体字セレクタが削除される場合があります。
以下はMaxLengthプロパティを「8」に設定し、親字「噌」を持つIVS文字「
」を入力可能な最大文字数を入力した場合の動作例です。
MaxLengthUnitの値 |
動作例 |
Char |
「 」は親字1文字、異体字セレクタ2文字の合計3文字としてカウントされます。よって、3文字目は親字のみの1文字が入力され、異体字セレクタ以降は削除されます。

|
Byte
|
「 」は親字2バイト、異体字セレクタ4バイトの合計6バイトとしてカウントされます。よって、2文字目は親字のみの2バイトが入力され、異体字セレクタ以降は削除されます。

|
TextElement |
IVS文字は1文字としてカウントされるため、8文字のIVS文字がすべて入力されます。

|
なお、GcComboBox.SelectionStartプロパティとGcComboBox.SelectionLengthプロパティは、MaxLengthUnitプロパティの設定にかかわらずMaxLengthUnit.Charでカウントした結果と同じ文字単位で処理されます。
編集モードの切り替え
CalendarGcComboBoxCellType.EditModeプロパティを使用します。
EditModeプロパティを使って、セルがフォーカスを受け取ったときのデフォルトの編集モードを定義できます。EditModeプロパティをEditMode.Insertにすると挿入モード、EditMode.Overwriteにすると上書きモードになります。また、EditMode.FixedInsertとEditMode.FixedOverwriteでは、編集モードが固定されるので、実行中に[Ins]キーが押されても編集モードは切り替わりません。
セルの編集時では、EditModeプロパティがEditMode.InsertまたはEditMode.Overwriteに設定されている場合、編集モードが[Ins]キーまたはプロパティによって変更されたときには、GcComboBox.EditStatusChangedイベントが発生します。また、GcComboBox.Overwriteプロパティを使って編集モードを調べることができます。
次のサンプルコードは、GcComboBox.KeyDownイベントで[Alt]キーおよび[C]キーが押下されたとき、GcComboBox.Overwriteプロパティを使用して編集モードを取得します。
Imports GrapeCity.Win.CalendarGrid
Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan
Imports CalendarGridInputMan = GrapeCity.Win.CalendarGrid.Editors
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim GcComboBoxCellType As New InputManCell.CalendarGcComboBoxCellType()
GcComboBoxCellType.DropDownStyle = CalendarGridComboBoxStyle.DropDown
GcComboBoxCellType.EditMode = InputMan.EditMode.Insert
Dim template As New CalendarTemplate()
template.RowCount = 3
template.ColumnHeader.Rows(0).Cells(0).DateFormat = "{DayOfWeek}"
template.Content.Rows(0).Cells(0).DateFormat = "{MonthDay}"
template.Content.Rows(0).Cells(0).CellStyleName = "defaultStyle"
template.Content.Rows(1).Cells(0).Name = "myCell1"
template.Content.Rows(1).Cells(0).CellType = GcComboBoxCellType.Clone()
template.Content.Rows(1).Cells(0).CellStyleName = "defaultStyle"
GcCalendarGrid1.Template = template
End Sub
Private Sub GcCalendarGrid1_EditingControlShowing(sender As Object, e As CalendarEditingControlShowingEventArgs) Handles GcCalendarGrid1.EditingControlShowing
If TypeOf e.Control Is CalendarGridInputMan.GcComboBox Then
RemoveHandler e.Control.KeyDown, AddressOf Editor_KeyDown
AddHandler e.Control.KeyDown, AddressOf Editor_KeyDown
End If
End Sub
Private Sub Editor_KeyDown(sender As Object, e As KeyEventArgs)
Dim editor As CalendarGridInputMan.GcComboBox = DirectCast(sender, CalendarGridInputMan.GcComboBox)
If e.Alt AndAlso e.KeyCode = Keys.C Then
If editor.OverWrite = True Then
Console.WriteLine("上書き")
Else
Console.WriteLine("挿入")
End If
End If
End Sub
using GrapeCity.Win.CalendarGrid;
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;
using CalendarGridInputMan = GrapeCity.Win.CalendarGrid.Editors;
private void Form1_Load(object sender, EventArgs e)
{
var gcComboBoxCellType = new InputManCell.CalendarGcComboBoxCellType();
gcComboBoxCellType.DropDownStyle = CalendarGridComboBoxStyle.DropDown;
gcComboBoxCellType.EditMode = InputManCell.EditMode.Insert;
var template = new CalendarTemplate();
template.RowCount = 3;
template.ColumnHeader.Rows[0].Cells[0].DateFormat = "{DayOfWeek}";
template.Content.Rows[0].Cells[0].DateFormat = "{MonthDay}";
template.Content.Rows[0].Cells[0].CellStyleName = "defaultStyle";
template.Content.Rows[1].Cells[0].Name = "myCell1";
template.Content.Rows[1].Cells[0].CellType = gcComboBoxCellType.Clone();
template.Content.Rows[1].Cells[0].CellStyleName = "defaultStyle";
gcCalendarGrid1.Template = template;
gcCalendarGrid1.EditingControlShowing += gcCalendarGrid1_EditingControlShowing;
}
private void gcCalendarGrid1_EditingControlShowing(object sender, CalendarEditingControlShowingEventArgs e)
{
if (e.Control is CalendarGridInputMan.GcComboBox)
{
e.Control.KeyDown -= new KeyEventHandler(Editor_KeyDown);
e.Control.KeyDown += new KeyEventHandler(Editor_KeyDown);
}
}
private void Editor_KeyDown(object sender, KeyEventArgs e)
{
var editor = sender as CalendarGridInputMan.GcComboBox;
if (e.Alt && e.KeyCode == Keys.C)
{
if (editor.OverWrite == true)
{
Console.WriteLine("上書き");
}
else
{
Console.WriteLine("挿入");
}
}
}
イベントを使った文字列操作
InputManと共通です。セルの編集時のみ有効です。GcComboBox.TextChangingイベントを使用します。
セルに文字列を入力するとGcComboBox.TextChangingイベントが、GcComboBox.TextChangedイベントの前(入力された文字列がText プロパティに渡される前)に発生します。このイベント内で入力文字列をチェックすれば、Textプロパティの値に影響を与えることなく、入力を制御できます。
コンテキストメニューの切り替え
CalendarGridの他のセル型の場合と同様です。CalendarGcComboBoxCellType.ContextMenuStripプロパティを使用します。
関連トピック